//
//  NewsViewController.m
//  coba-iOS
//
//  Created by 郭四虎 on 15/12/9.
//  Copyright © 2015年 YouKu. All rights reserved.
//

#import "NewsViewController.h"
#import "SUNSlideSwitchView.h"
#import "SortModel.h"
#import "NewsListViewController.h"
#import "NewsDetailViewController.h"
#import "AppDelegate.h"
#import "RedPacketController.h"

@interface NewsViewController ()<SUNSlideSwitchViewDelegate,GDTSplashAdDelegate>
{
    SUNSlideSwitchView *_slideView;
    
    NSMutableArray *_dataArr;
    
    NewsListViewController *_vc;
    
        BOOL _shouldHide;
        BOOL _isThirdAD;
        BOOL _haveClicked;
        
        NSMutableArray *_loadingArr;
        
        UIImageView *_adIma;
        UIImage *_launchimage;
        
        GDTSplashAd *_splash;
        UIWindow *fK;
    
    UIButton *_RPbtn;
    UIButton *_showRPbtn;
    
    MyRedPacket *_rp;
}
@property(nonatomic, assign)BOOL statusBarHide;
@property(nonatomic, strong)NSMutableArray *controllers;
@end

@implementation NewsViewController

- (void)setStatusBarHide:(BOOL)statusBarHide
{
    _statusBarHide = statusBarHide;
    [self prefersStatusBarHidden];
    [self setNeedsStatusBarAppearanceUpdate];
}
//-(UIStatusBarStyle)preferredStatusBarStyle
//{
//    return UIStatusBarStyleLightContent;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
//    Class c =NSClassFromString(@"LSApplicationWorkspace");
//    id s = [(id)c performSelector:NSSelectorFromString(@"defaultWorkspace")];
//    NSArray *array = [s performSelector:NSSelectorFromString(@"allInstalledApplications")];
//    for (id item in array)
//    {
//        NSLog(@"%@",[item performSelector:NSSelectorFromString(@"applicationIdentifier")]);
//        //NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleIdentifier")]);
//        NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleVersion")]);
//        NSLog(@"%@",[item performSelector:NSSelectorFromString(@"shortVersionString")]);
//    }
    
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(startCollect) name:@"startcollect" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(endCollect) name:@"endcollect" object:nil];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"新闻";

    self.view.backgroundColor = RGBcolor(245, 245, 245);
    
    _dataArr = [NSMutableArray array];
    _controllers = [NSMutableArray array];
    [self initUI];
    [self getList];
//    [MyAFN POST:@"http://a.cooba.cc/macmark.json" parameters:nil block:^(id responseObject) {
//        
//        NSDictionary *res = responseObject;
//        NSLog(@"%@",res);
//    }fromController:self];
    
    if ([SHOWAD boolValue]) {
        [self loadAd];
    }
}

- (void)startCollect
{
    NSLog(@"----------------start");
    [self workBlock:_myscroll with:_myarr];
}

- (void)endCollect
{
    NSLog(@"----------------end");
    
    [self restBlock:_myscroll];
}

- (void)getList
{
    
    NSArray *titleArr = @[@"热点",@"社会",@"娱乐",@"生活",@"美文"];
    NSArray *idArr = @[@"inland",@"internat",@"picture",@"local",@"peri"];
    
    for (int i = 0; i < 5; i++) {
        SortModel *model = [[SortModel alloc]init];
        model.sortid = [idArr objectAtIndex:i];
        model.name = [titleArr objectAtIndex:i];
        [_dataArr addObject:model];
    }
    [self initControllers];
}

- (void)initControllers
{
    NSArray *arr = @[@"hot_new",@"society_new",@"relax_new",@"life_new",@"love_new"];
    
    for (int i = 0; i<arr.count; i++) {
        NSString *adkey = arr[i];
        SortModel *model = _dataArr[i];
        
        NewsListViewController *controller = [[NewsListViewController alloc]init];
        controller.containedVC = self;
        controller.adkey = adkey;
        controller.title = model.name;
        controller.model = model;
        controller.passModel = ^(NewsModel *newsModel){
            
            NewsDetailViewController *detail = [[NewsDetailViewController alloc]init];
            detail.model = newsModel;
            
            
            [self.navigationController pushViewController:detail animated:YES];
//            if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//                self.navigationController.interactivePopGestureRecognizer.delegate = nil;
//            }
        };
        
        //统计广告
        controller.collectAd = ^(SDCycleScrollView *scroll,NSArray *arr,BOOL isError){
            
            
            if (scroll) {
                _myscroll = scroll;
                _myarr = arr;
                _isError = isError;
                [self workBlock:scroll with:arr];
            }else{
                
                [self restBlock:_myscroll];
                _myscroll = nil;
            }
            
        };
        //点击广告
        controller.myad = ^(BannerModel *model){
            
            [MyAd collectClickAd:model];
            
            AdViewController *controller = [[AdViewController alloc]init];
            
            if (![model.href hasPrefix:@"http://"]&&![model.href hasPrefix:@"https://"]) {
                
                model.href = [NSString stringWithFormat:@"http://%@",model.href];
            }
            
            controller.urlstr = model.href;
            [self.navigationController pushViewController:controller animated:YES];
        };
        [_controllers addObject:controller];
    }
    [_slideView buildUI];
}

- (void)initUI
{
    CGRect rect = self.view.bounds;
    rect.origin.y += 20;
//    rect.size.height -= 64;
    _slideView = [[SUNSlideSwitchView alloc]initWithFrame:rect];
    _slideView.slideSwitchViewDelegate = self;
    
    _slideView.tabItemNormalColor = [UIColor lightGrayColor];
    //_slideView.tabItemSelectedColor = [SUNSlideSwitchView colorFromHexRGB:@"bb0b15"];
    //_slideView.shadowImage = [UIImage imageNamed:@"red_line_and_shadow@2x.png"];
    [self.view addSubview:_slideView];
    
    
    __weak NewsViewController *vc = self;
    _slideView.getIndex = ^(NSInteger i){
        
        ListViewController *list = vc.controllers[i];
        _myscroll = list.scrollView;
        [vc workBlock:list.scrollView with:list.adArr];
        
        _vc = _controllers[i];
        [vc updateTable];
    };
    
    [self showRedPacket];
}

- (void)showRedPacket
{
    
    [MyRedPacket haveRedPacket:^(BOOL havePacket,NSString *firstT,NSString *lastT) {
        
        if (havePacket) {
            
            if ([lastT isEqualToString:@""]) {
                return;
            }
            
            NSDateFormatter *df = [[NSDateFormatter alloc]init];
            [df setDateFormat:@"HH:mm:ss"];
            NSDate *begindate = [df dateFromString:firstT];
            NSDate *enddate = [df dateFromString:lastT];
            
            NSDate *now = [df dateFromString:[df stringFromDate:[NSDate date]]];
            
            
            NSTimeInterval begin = [begindate timeIntervalSinceDate:now];
            NSTimeInterval end = [enddate timeIntervalSinceDate:now];
            
            if (end>0) {
                //活动未结束
                if (begin>0) {
                    //活动未开始
                    [self performSelector:@selector(addRedBtn) withObject:nil afterDelay:begin];
                    
                }else{
                    
                    [self addRedBtn];
                }
                
                [_RPbtn performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:end];
            }
        }
    }];
}

- (void)addRedBtn
{
    _RPbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _RPbtn.frame = CGRectMake(WIDTH-50-20, HEIGHT/2, 50, 50);
    _RPbtn.layer.cornerRadius = 10;
    _RPbtn.clipsToBounds = YES;
    [_RPbtn setBackgroundImage:[UIImage imageNamed:@"1449140061"] forState:UIControlStateNormal];
    [_RPbtn addTarget:self action:@selector(toTop) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view insertSubview:_RPbtn belowSubview:_adIma];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    [_RPbtn addGestureRecognizer:pan];
}
- (void)handlePan:(UIPanGestureRecognizer *)pan
{
    CGPoint origin = pan.view.frame.origin;
    CGSize size = pan.view.frame.size;
    
    CGPoint translation = [pan translationInView:self.view];
    pan.view.center = CGPointMake(pan.view.center.x + translation.x,
                                  pan.view.center.y + translation.y);
    
    [pan setTranslation:CGPointZero inView:self.view];
    if (pan.state == UIGestureRecognizerStateEnded) {
        
        if (origin.y < 50) {
            
            
            if ((origin.x+size.width/2)<=WIDTH/2){
                
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(20, 50, size.width, size.height);
                }];
            }else{
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(WIDTH - size.width-20, 50, size.width, size.height);
                }];
            }
        }else if(origin.y > HEIGHT-100){
            
            if ((origin.x+size.width/2)<=WIDTH/2){
                
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(20, HEIGHT-100, size.width, size.height);
                }];
            }else{
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(WIDTH - size.width-20, HEIGHT-100, size.width, size.height);
                }];
            }
            
            
        }else{
            
            if ((origin.x+size.width/2)<=WIDTH/2){
                
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(20, origin.y, size.width, size.height);
                }];
            }else{
                [UIView animateWithDuration:0.2 animations:^{
                    
                    pan.view.frame = CGRectMake(WIDTH - size.width-20, origin.y, size.width, size.height);
                }];
            }
        }
        
    }
}
- (void)updateTable
{
    for (NewsListViewController *list in _controllers) {
        
        list.tableView.scrollsToTop = NO;
    }
    _vc.tableView.scrollsToTop = YES;
}

- (void)toTop
{
    if (![Myuser sharedUser].login_id) {
        
        [self.view Message:@"请登录"];
        return;
    }
    [_RPbtn removeFromSuperview];
    
    
    _showRPbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _showRPbtn.layer.cornerRadius = 25;
    _showRPbtn.backgroundColor = [UIColor yellowColor];
    [_showRPbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_showRPbtn setTitle:@"开" forState:UIControlStateNormal];
    [_showRPbtn addTarget:self action:@selector(showRedPaketDetail) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *backV = [[UIView alloc]initWithFrame:SCREEN];
    backV.tag = 666;
    backV.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:0.7];
    [self.view addSubview:backV];
    
    UIImageView *ima = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/2-100, HEIGHT/2-150, 200, 300)];
    ima.userInteractionEnabled = YES;
    ima.image = [UIImage imageNamed:@"redwallet"];
    _showRPbtn.frame = CGRectMake(ima.width/2-25, ima.height-70, 50, 50);
    
    [backV addSubview:ima];
    
    [ima addSubview:_showRPbtn];
}

- (void)showRedPaketDetail
{
    [MyRedPacket getRedPacket:^(BOOL suc, MyRedPacket *rp) {
        
//        if (suc) {
//            
//            _rp = rp;
//
//        }else{
//            _rp = [[MyRedPacket alloc]init];
//        }
        _rp = rp;
        
    }];
    
    [self animation:^(bool finished) {
       
        if (finished) {
            
            NSLog(@"%@",_rp);
            if (_rp) {
                
                RedPacketController *vc = [[RedPacketController alloc]init];
                vc.rp = _rp;
                vc.back = ^{
                    
                    AdViewController *controller = [[AdViewController alloc]init];
                    
                    if (![_rp.url hasPrefix:@"http://"]&&![_rp.url hasPrefix:@"https://"]) {
                        
                        _rp.url = [NSString stringWithFormat:@"http://%@",_rp.url];
                    }
                    
                    controller.urlstr = _rp.url;
                    [self.navigationController pushViewController:controller animated:YES];
                };
                [self presentViewController:vc animated:YES completion:nil];
            }
            [[self.view viewWithTag:666]removeFromSuperview];
            [self.view insertSubview:_RPbtn belowSubview:_adIma];
            [_showRPbtn removeFromSuperview];
        }
    }];
    
}

- (void)animation:(void(^)(bool finished))back
{
    [UIView animateWithDuration:1
                          delay:0
                        options:0
                     animations:^{
                         
                         CATransform3D rotate = CATransform3DMakeRotation(M_PI, 0, 1, 0);
                         
                         _showRPbtn.layer.transform = rotate;
                     }
                     completion:^(BOOL finished) {
                         
                         _showRPbtn.layer.transform = CATransform3DMakeRotation(0, 0, 0, 0);
                         if (!_rp) {
                             [self animation:^(bool finished) {
                                 if (finished) {
                                     back(YES);
                                 }
                             }];
                         }else{
                             back(YES);
                         }
                         
                     }];
}

- (NSUInteger)numberOfTab:(SUNSlideSwitchView *)view
{
    return _controllers.count;
}

- (UIViewController *)slideSwitchView:(SUNSlideSwitchView *)view viewOfTab:(NSUInteger)number
{
    return _controllers[number];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //UITouch *touch = [touches anyObject];
    NSLog(@"aaa");
}

- (void)workBlock:(SDCycleScrollView *)view with:(NSArray *)arr
{
    [self restBlock:_vc.scrollView];
    if (self.tabBarController.selectedIndex != 0) {
        
        return;
    }
    if (!arr.count||!view) {
        
        return;
    }
    NSLog(@"开始统计");
    __weak NSArray *slide = arr;
    view.getContentOffset = ^(float offset){
        
        if (!_isError) {
            int i;
            
            if (offset == 0) {
                
                i = 0;
            }else{
                int index = offset/WIDTH;
                i = index%arr.count ;
            }
            
            NSLog(@"++++%d",i);
            if (i<slide.count) {
                BannerModel *model = slide[i];
                [MyAd collectShowAd:model];
            }
            
        }
    };
}

- (void)restBlock:(SDCycleScrollView *)view
{
    NSLog(@"不统计了》》》》》》》");
    if (view) {
        view.getContentOffset = ^(float offset){
            
            
        };
    }
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self restBlock:_myscroll];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    if (_myscroll) {
        
        [self workBlock:_myscroll with:_myarr];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (_shouldHide) {
        
        //self.navigationController.navigationBarHidden = YES;
        self.tabBarController.tabBar.hidden = YES;
    }else{
        //self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = NO;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark load
- (void)loadAd{
    _isError = NO;
    _haveClicked = NO;
    _loadingArr = [NSMutableArray array];
    self.statusBarHide = YES;
    
    getLaunchImage(_launchimage);
    if ([SHOWAD boolValue]) {
        [self showBtn];
        
        [MyCar isBus:^(bool isbus) {
            NSLog(@"qqqqq%d",isbus);
            if (isbus) {
                [[NSUserDefaults standardUserDefaults]setObject:@(1) forKey:@"isbus"];
                
            }else
            {
                [[NSUserDefaults standardUserDefaults]setObject:@(0) forKey:@"isbus"];
            }
            
            [[MyAd sharedMyad]getDataWithTag:@"loadpage" back:^(NSDictionary *dic) {
                _isError = NO;
                self.statusBarHide = YES;
                
                [self analyzeData:dic];
            } error:^(NSError *error,NSDictionary *di) {
                _isError = YES;
                
                self.statusBarHide = NO;
                
                
                [self analyzeData:di];
            }];
            
            
        }];
        
    }else{
        
        //        if (self.dataDic.count) {
        //
        //            [self analyzeData:self.dataDic];
        //        }
    }
    [self autoLogin];
}
- (void)autoLogin
{
    if (!USERID) {
        return;
    }
    NSDictionary *dic = @{@"login_id":USERID};;
    
    //    if ([self valiMobile:USERID]) {
    //        dic = @{@"login_id":USERID};
    //    }else{
    //        dic = @{@"login_id":USERID};
    //    }
    [MyAFN POST:USERINFO parameters:dic block:^(id responseObject) {
        NSDictionary *response = responseObject;
        
        if ([response objectForKey:@"status"]) {
            
            [[Myuser sharedUser]setValuesForKeysWithDictionary:response];
            
            NSString *loginid;
            if ([response objectForKey:@"login_id"]) {
                
                loginid = [response objectForKey:@"login_id"];
            }else{
                
                loginid = [response objectForKey:@"uuid"];
            }
            [[NSUserDefaults standardUserDefaults]setObject:loginid forKey:@"userid"];
            [Myuser sharedUser].login_id = loginid;
            
            //            [[NSUserDefaults standardUserDefaults]setObject:[MyMD5 md5:@"123456"] forKey:@"userpwd"];
            
            NSString *myname;
            if ([response objectForKey:@"name"]) {
                myname = [response objectForKey:@"name"];
                
            }
            [Myuser sharedUser].name = myname;
            
            NSString *url;
            if ([response objectForKey:@"photo"]) {
                
                //url = [NSString stringWithFormat:@"%@?url=%@",GETICON,[response objectForKey:@"photo"]];
                url = [response objectForKey:@"photo"];
            }
            [[NSUserDefaults standardUserDefaults]setObject:url forKey:@"usericon"];
            [Myuser sharedUser].icon = url;
            
        }else{
            [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"userid"];
            [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"usericon"];
            [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"username"];
            [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"userpwd"];
        }
        
    } error:^(NSError *error) {
        
        [[Myuser sharedUser]cleanUser];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeUserinfo" object:nil];
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"userid"];
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"usericon"];
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"username"];
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"userpwd"];
        
    } fromController:nil];
}
- (void)showBtn
{
    
   // self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
    _shouldHide = YES;
    
    _adIma = [[UIImageView alloc]initWithFrame:SCREEN];
    _adIma.userInteractionEnabled = YES;
    
    
    if ([SHOWAD boolValue]) {
        
        _isThirdAD = YES;
        _adIma.image = _launchimage;
        [self.view addSubview:_adIma];
        [self.view bringSubviewToFront:_adIma];
    }
}
- (BOOL)prefersStatusBarHidden
{
    if (_statusBarHide) {
        return YES;
    }else{
        return NO;
    }
}

- (void)analyzeData:(NSDictionary *)data
{
    for (NSDictionary *dic in [data objectForKey:@"bannerList"]) {
        
        BannerModel *model = [[BannerModel alloc]init];
        [model setValuesForKeysWithDictionary:dic];
        
        if (model.path.integerValue == 0) {
            [_loadingArr addObject:model];
        }
    }
    [self showClose];
    
}
- (void)showClose
{
    UIImage *ima = _launchimage;
    
    if (!_loadingArr.count) {
        //有网没广告
        [self dismissBtn];
        
        self.statusBarHide = YES;
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        fK = delegate.window;
        
        
        if ([SHOWAD boolValue]) {
            
            
            
            _splash = [[GDTSplashAd alloc] initWithAppkey:GGTID placementId:@"7000812135592948"];
            _splash.backgroundColor = [UIColor colorWithPatternImage:_launchimage];
            _splash.delegate = self;
            
            
            //设置开屏拉取时长限制，若超时则不再展示广告
            _splash.fetchDelay = 3;
            
            //拉取并展示
            [_splash loadAdAndShowInWindow:fK];
        }
        return;
    }
    BannerModel *model = _loadingArr[0];
    NSString *str;
    if ([ISBUS boolValue]) {
        str = [NSString stringWithFormat:@"%@%@",CAR_URL,model.home_pic];
    }else{
        str = model.home_pic;
    }
    [_adIma sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:ima completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        
        [self performSelector:@selector(dismissBtn) withObject:nil afterDelay:DELAYTIME];
        
        if (!image) {
            
            //_adIma.image = [UIImage imageNamed:@"广告2.jpg"];
        }else{
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showAd)];
            [_adIma addGestureRecognizer:tap];
            
            UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
            UIVisualEffectView *effectvi = [[UIVisualEffectView alloc]initWithEffect:effect];
            effectvi.frame = CGRectMake(WIDTH - 70, 30, 60, 30);
            effectvi.layer.cornerRadius = 10;
            effectvi.clipsToBounds = YES;
            [_adIma addSubview:effectvi];
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setFrame:CGRectMake(0, 0, 60, 30)];
            [btn setTitle:@"跳过广告" forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:13];
            //btn.backgroundColor = [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1];
            btn.backgroundColor = [UIColor clearColor];
            btn.layer.cornerRadius = 10;
            [btn addTarget:self action:@selector(dismissBtn) forControlEvents:UIControlEventTouchUpInside];
            [effectvi addSubview:btn];
            
            [MyAd collectShowAd:model];
        }
        UIImageView *imaview = [[UIImageView alloc]initWithFrame:CGRectMake(0, HEIGHT - WIDTH*2/7, WIDTH, WIDTH*2/7)];
        imaview.image = [UIImage imageNamed:@"广告.jpg"];
        [_adIma addSubview:imaview];
    }];
}
- (void)showAd
{
    BannerModel *model = _loadingArr[0];
    [MyAd collectClickAd:model];
    
    _haveClicked = YES;
    
    [self dismissBtn];
    AdViewController *ad = [[AdViewController alloc]init];
    ad.urlstr = model.href;
    
    [self.navigationController pushViewController:ad animated:YES];
}
- (void)dismissBtn
{
    self.statusBarHide = NO;
    
    [UIView animateWithDuration:0.5 animations:^{
        
        _adIma.alpha = 0;
        
    } completion:^(BOOL finished) {

        _shouldHide = NO;
        
        if (!_haveClicked) {
            
            //self.navigationController.navigationBarHidden = NO;
            self.tabBarController.tabBar.hidden = NO;
        }else{
            //self.navigationController.navigationBarHidden = YES;
            self.tabBarController.tabBar.hidden = YES;
        }
        
        
        [_adIma removeFromSuperview];
    }];
}

- (void)splashAdWillPresentFullScreenModal:(GDTSplashAd *)splashAd
{
    
    NSLog(@"%s",__FUNCTION__);
}
/**
 *  点击以后全屏广告页已经被关闭
 */
- (void)splashAdDidDismissFullScreenModal:(GDTSplashAd *)splashAd
{
    
    NSLog(@"%s",__FUNCTION__);
}
-(void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd
{
    self.statusBarHide = NO;
    //[self prefersStatusBarHidden];
    _isThirdAD = NO;
    
    NSLog(@"%s",__FUNCTION__);
    
}

-(void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
{
    self.statusBarHide = NO;
    
    NSLog(@"%s%@",__FUNCTION__,error);
    
}
-(void)splashAdClicked:(GDTSplashAd *)splashAd
{
    
    NSLog(@"%s",__FUNCTION__);
}

-(void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd
{
    
    NSLog(@"%s",__FUNCTION__);
}

-(void)splashAdClosed:(GDTSplashAd *)splashAd
{
    
    NSLog(@"%s",__FUNCTION__);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
